﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hp.Vertica.Migration.SqlServer
{
    abstract class SqlDataTypeWithPrecision : SqlDataType
    {
        public abstract Int32 MinPrecision { get; }
        public abstract Int32 MaxPrecision { get; }
        public abstract Int32 DefaultPrecision { get; }

        public SqlDataTypeWithPrecision()
        {
            this.Precision = this.DefaultPrecision;
        }

        public SqlDataTypeWithPrecision(Int32 precision)
        {
            this.Precision = precision;
        }

        public override int Precision
        {
            get
            {
                return base.Precision;
            }
            set
            {
                base.Precision = value < this.MinPrecision ? this.MinPrecision : (value > this.MaxPrecision ? this.MaxPrecision : value);
            }
        }

        public override string ToString()
        {
            if (this.Precision == this.DefaultPrecision)
            {
                return this.Name;
            }
            else
            {
                return this.Name + "(" + this.Precision + ")";
            }
        }
    }
}
